home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok15.lha
/
Seafarers_Manual
/
Source
/
C2P6.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
1KB
|
39 lines
MODULE C2P6; (* Chapter 2 Problem 6 *)
(* Calculate area of a triangle *)
(* From the book "Modula-2 A Seafarer's Manual and Shipyard Guide" *)
(* Page 41 adapted "M2Amiga Modula-2" 26 Feb 1988 *)
FROM InOut IMPORT WriteLn,
WriteString;
FROM RealInOut IMPORT ReadReal,
WriteReal;
FROM MathLib0 IMPORT sqrt;
VAR
a, b, c, (* sides of triangle *)
s, (* help variable for calculation *)
area : REAL; (* area of triangle *)
BEGIN
WriteString ("Calculate area of a triangle: ");
WriteLn; WriteLn; WriteLn;
WriteString ("Enter length of side a in inch: ");
ReadReal (a);
WriteString ("Enter length of side b in inch: ");
ReadReal (b);
WriteString ("Enter length of side c in inch: ");
ReadReal (c);
WriteLn; WriteLn;
(* Calculation area of triangle with formula
a = square root [s * (s-a) * (s-b) * (s-c)]
where s = (a+b+c) / 2 *)
s := (a + b + c) / 2.0;
area := sqrt(s * (s-a) + (s-b) * (s-c));
WriteString ("The area of the triangle is ");
WriteReal (area,10,3);
WriteString (" square inch");
WriteLn;
END C2P6.